<?php
/*
 * 快递100API
 */
namespace yunsms;

use app\common\model\System;

class Yunsms
{
    //单独发送
    public static function Send($config,$param)
    {
        $url='http://cloud.yunsms.cn/v2sms.aspx?action=send&rt=json';
        $post_data = array();
        $post_data['userid']    = $config['smsid'];//用户ID。
        $post_data['sign']      = $config['smskey'];//密钥。
        $post_data['timestamp'] = '19700101000000';
        $post_data['content']   = $param['content'].'【'.$config['sign'].'】'; //短信内容
        $post_data['mobile']    = $param['mobile'];
        return self::request($url,$post_data);
        
    }
    //查询余额
    public static function Overage($config){
        $url='http://cloud.yunsms.cn/v2sms.aspx?action=overage&rt=json';
        $post_data = array();
        $post_data['userid'] = $config['smsid'];//用户ID。
        $post_data['timestamp'] = '19700101000000';
        $post_data['sign'] = $config['smskey'];//密钥。
        return self::request($url,$post_data);
        
    }
    //请求短信平台
    protected static function request($url,$post_data){
        $o='';
        foreach ($post_data as $k=>$v)
        {
           $o.="$k=".urlencode($v).'&';
        }
        $data = substr($o,0,-1);
        $res = json_to_array(https_request($url, $data));
        return $res;
    }

}
